/* 
 * Copyright 2007 Steven Osborn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.lenovo.leos.filebrowser.engine.model;

import java.util.Comparator;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import com.lenovo.leos.filebrowser.engine.util.FileClipBoard;
import com.lenovo.leos.filebrowser.engine.util.HzToPy;
import com.lenovo.leos.filebrowser.engine.util.Log;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;


/*
 *  the class used in file browser
 *  it is used by adapter to fill the item view 
 *  which will shown to user
 */

public class IconifiedText extends Object implements Comparable<IconifiedText> {
	private static final String TAG = "IconifiedText";

	// it will be remove
	private static FileClipBoard mfcbMarkedFile = FileClipBoard.getInstance();

	private String mName = "";
	private String mType = "";
	private String mText = "";
	private Drawable mIcon;
	private File mFile = null;
	private long mSize = 0;
	private long mTime = 0;
	private View mvItem = null;
	
	private boolean isCut = false;
	private boolean isSysDir = false;//[improve] maybe remove
	private boolean isSelected = false; //[improve] add it again

	
	// new construction
//	public IconifiedText(File file){
//		
//	}

	// remove isSysDir
	public IconifiedText(Drawable icon, File file, boolean isSysDir) {
		mIcon = icon;
		mName = file.getName();
		mText = file.getName();
		mFile = file;
		mSize = file.length();
		mTime = file.lastModified();
		mType = "";
		isSysDir = isSysDir;

		// remove it 
		if (mfcbMarkedFile.hasIt(file)) {
			// if the file is selected and to be cut, set is cut flag to ture.
			if (mfcbMarkedFile.getOperation() == FileClipBoard.OP_CUT) {
				Log.i(TAG, "set it cut flag");
				setIsCut(true);
			}
		}
		if (null != mfcbMarkedFile.getSelected()) {
			if (mfcbMarkedFile.getSelected().getAbsolutePath().equals(file.getAbsolutePath())) {
				setIsSelected(true);
			}else
				setIsSelected(false);
		}
	}

	// [improve]maybe remove
	public IconifiedText(Drawable icon, File file, String type,
			boolean isSysDir) {
		this(icon, file, isSysDir);
		setType(type);
	}

	
	// [improve]check type
	public void setType(String type) {
		mType = type;
	}
	
	public String getType() {
		return mType;
	}
	
	public View getView () {
		return mvItem;		
	}
	
	public void setView (View v) {
		mvItem = v;
	}

	public boolean isSysDir() {
		return isSysDir;
	}

	public void setIsCut(boolean iscut) {
		isCut = iscut;
	}

	public boolean getIsCut() {
		return isCut;
	}

	public long getTime() {
		return mTime;
	}

	public long getSize() {
		return mSize;
	}

	public File getFile() {
		return mFile;
	}

	public String getName() {
		return mName;
	}

	public String getText() {
		return mText;
	}

	public void setIcon(Drawable icon) {
		mIcon = icon;
	}

	public Drawable getIcon() {
		return mIcon;
	}
	
	public boolean getIsSelected() {
		return isSelected;
	}
	
	public void setIsSelected(boolean isSel){
		isSelected = isSel;
	}

	//[improve] it is wrong
	// @Override
	public int compareTo(IconifiedText other) {
		if (mName != null)
			return mName.compareTo(other.getName());
		else
			throw new IllegalArgumentException();
	}
}












